<?php
namespace app\admin\controller;

use think\Db;
use think\Model;

/**
 * 管理员日志
 */
class AdminLog extends Base
{
    /**
     * @throws
     * 日志列表
     */
    public function lists()
    {
        $model = Model("AdminLog");

        // 获取配置信息
        $conf = config();

        // 分页信息
        $pageSize   = input('limit')    ? input('limit')    : 20;

        // 查询数据
        $list = $model->order("id desc")->paginate($pageSize);

        $this->assign('total',$list->total());
        $this->assign('page',$list->render());
        $this->assign('list',$list);

        return $this->fetch();
    }


    /**
     * @throws
     * 详情
     */
    public function info()
    {
        $model = Model("AdminLog");

        $id = input('id');

        $info = $model->where("id",$id)->find()->toArray();

        $data = json_decode($info['data'],true);

        echo "<pre/>";
        print_r($data);

    }


    /**
     * 添加日志
     */
    public function add($note,$data,$act)
    {
        $model = Model("AdminLog");

        $log['admin_id']	= $this->admin_id;
        $log['admin_name']  = $this->user_name;
        $log['route'] 		= request()->module() . '/' . request()->controller() . '/' . request()->action();
        $log['act']         = $act;
        $log['note'] 		= $note;
        $log['data'] 		= json_encode($data);
        $log['ip'] 			= request()->ip();
        $log['create_time'] = time();

        $model->insert($log);
    }


}
